<?php

namespace GeorgRinger\News\ViewHelpers;

/**
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */

/**
 * ViewHelper to render the page title
 *
 * # Example: Basic Example
 * # Description: Render the content of the VH as page title
 * <code>
 *	<n:titleTag>{newsItem.title}</n:titleTag>
 * </code>
 * <output>
 *	<title>TYPO3 is awesome</title>
 * </output>
 *
 */
class TitleTagViewHelper extends \TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper {

	/**
	 * Override the title tag
	 *
	 * @return void
	 */
	public function render() {
		$content = trim($this->renderChildren());
		if (!empty($content)) {
			$GLOBALS['TSFE']->altPageTitle = $content;
			$GLOBALS['TSFE']->indexedDocTitle = $content;
		}
	}
}
